package com.keyancompany.zhongbaopingtai.api;

import com.keyancompany.zhongbaopingtai.ConstansUrl;
import com.keyancompany.zhongbaopingtai.Constants;
import com.keyancompany.zhongbaopingtai.listener.IAsyncHttpResponseHandler;
import com.keyancompany.zhongbaopingtai.listener.LoadingHanlder;
import com.loopj.android.http.RequestParams;

/**
 * Created by lyh on 2016/10/11.
 */
public class FriendsAPI extends BaseAPI {
    public static final int FRIENDS_LIST_ALL = 0X510;

    public static final int FRIENDS_LIST = 0X511;

    public static final int ADD_FRIEND = 0X512;

    public static final int ADD_FRIEND_REQUEST = 0X513;

    public static final int SEARCH_FRIENDS = 0X514;

    public static final int LETTER_LIST = 0x515;

    public static final int SEND_LETTER = 0x516;

    public static final int ADD_EXPERTS = 0x517;

    public static final int SELECT_EXPERTS = 0x518;

    public static final int TEAM_ADD_USER = 0x519;

    public static final int RY_SEND_MSG_REQUEST = 0x520;

    public static final int OU_TEAM = 0x521;

    public static final int OTHER_TEAM_MEMBER = 0x522;

    /**
     * 获取好友列表
     *
     * @param current
     * @param handler
     * @param loading
     */
    public static final void getFriendsList(int current, IAsyncHttpResponseHandler handler, LoadingHanlder loading) {
        RequestParams params = new RequestParams();
        params.put("userId", UserAPI.getUserId());
        params.put("current", current + "");
        params.put("pageSize", "200");
        params.put("friendClass", "all");
        post(ConstansUrl.FRIENDS_LIST, params, handler, FRIENDS_LIST, loading);
    }

    /**
     * 获取好友列表
     *
     * @param handler
     * @param loading
     */
    public static final void getFriendsListAll(IAsyncHttpResponseHandler handler, LoadingHanlder loading) {
        RequestParams params = new RequestParams();
        params.put("userId", UserAPI.getUserId());
        params.put("friendClass", "all");
        get(ConstansUrl.FRIENDS_LIST_ALL, params, handler, FRIENDS_LIST_ALL, loading);
    }


    public static final void addFriennds(String acceptPid, IAsyncHttpResponseHandler handler, LoadingHanlder loading) {
        RequestParams params = new RequestParams();
        params.put("userId", UserAPI.getUserId());
        params.put("acceptPid", acceptPid);
        post(ConstansUrl.ADD_FRIEND, params, handler, ADD_FRIEND, loading);
    }

    /**
     * 被邀请者处理好友请求
     *
     * @param msgpid
     * @param state
     * @param handler
     * @param loading
     */
    public static final void addRequestFriends(String msgpid, int state, IAsyncHttpResponseHandler handler, LoadingHanlder loading) {
        RequestParams params = new RequestParams();
        params.put("userId", UserAPI.getUserId());
        params.put("msgpid", msgpid);
        params.put("state", state + "");
        post(ConstansUrl.ADD_FRIEND_REQUEST, params, handler, ADD_FRIEND_REQUEST, loading);
    }

    /**
     * 搜索好友
     *
     * @param current
     * @param keyword
     * @param handler
     * @param loading
     */
    public static final void searchFriends(int current, String keyword, IAsyncHttpResponseHandler handler, LoadingHanlder loading) {
        RequestParams params = new RequestParams();
        params.put("userId", UserAPI.getUserId());
        params.put("current", current + "");
        params.put("pageSize", DETAULT_COUNT + "");
        params.put("search", keyword);
        post(ConstansUrl.SEARCH_FRIENDS, params, handler, SEARCH_FRIENDS, loading);
    }

    /**
     * userId：用户id
     * current：当前页
     * type：消息类型（0系统消息，1项目信息，2个人消息）
     * isread：是否阅读0否1是
     * headpic:头像
     *
     * @param handler
     * @param loadingHandler
     */
    public static void getLetterList(int current, IAsyncHttpResponseHandler handler, LoadingHanlder loadingHandler) {

        RequestParams params = new RequestParams();
        params.put("userId", UserAPI.getUserId());
        params.put("current", "" + current);
//        params.put("type");
        post(ConstansUrl.LETTER_LIST, params, handler, LETTER_LIST, loadingHandler);
    }

    /**
     * userId=用户pid
     * type=消息类型（0系统消息，1项目信息，2个人消息）
     * fromUser=好友pid
     * isread=是否已读（0未读，=1已读）
     *
     * @param fromUser
     * @param handler
     * @param loadingHandler
     */
    public static void getLetterListByPid(int type, String fromUser, IAsyncHttpResponseHandler handler, LoadingHanlder loadingHandler) {

        RequestParams params = new RequestParams();
        params.put("userId", UserAPI.getUserId());
        params.put("type", "" + type);
        params.put("fromUser", fromUser);
//        params.put("isread", "" + type);

        post(ConstansUrl.LETTER_LIST_PID, params, handler, LETTER_LIST, loadingHandler);
    }

    public static void sendLetter(String content, String toUser, IAsyncHttpResponseHandler handler, LoadingHanlder loadingHanlder) {

        RequestParams params = new RequestParams();
        params.put("userId", UserAPI.getUserId());
        params.put("content", "" + content);
        params.put("toUser", toUser);

        post(ConstansUrl.SEND_LETTER, params, handler, SEND_LETTER, loadingHanlder);
    }

    /**
     * 团队邀请
     *
     * @param msgId
     * @param userId
     * @param teamCode
     * @param forId
     * @param state
     * @param handler
     * @param loadingHanlder
     */
    public static void teamaddUser(String msgId, String userId, String forId, String teamCode, String state, IAsyncHttpResponseHandler handler, LoadingHanlder loadingHanlder) {

        RequestParams params = new RequestParams();
        params.put("msgId", msgId);
        params.put("userId", "" + userId);
        params.put("teamCode", teamCode);
        params.put("forId", forId);
        params.put("state", state);

        post(ConstansUrl.TEAM_ADD_USER, params, handler, TEAM_ADD_USER, loadingHanlder);

    }

    /**
     * 好友添加
     *
     * @param userId
     * @param msgPid
     * @param state
     * @param handler
     * @param loadingHanlder
     */
    public static void addFriendRequest(String userId, String msgPid, String state, IAsyncHttpResponseHandler handler, LoadingHanlder loadingHanlder) {
        RequestParams params = new RequestParams();
        params.put("userId", "" + userId);
        params.put("msgpid", msgPid);
        params.put("state", state);

        post(ConstansUrl.SEND_LETTER, params, handler, SEND_LETTER, loadingHanlder);
    }

    public static void ouTeam(String msgPid, String userId, String forId, String teamId, String state, IAsyncHttpResponseHandler handler, LoadingHanlder loadingHanlder) {
        RequestParams params = new RequestParams();
//        params.put("msgId", UserAPI.getUserId());
        params.put("userId", "" + userId);
        params.put("msgId", msgPid);
        params.put("forId", forId);
        params.put("teamId", teamId);
        params.put("state", state);

        post(ConstansUrl.OU_TEAM, params, handler, OU_TEAM, loadingHanlder);
    }


    public static void rysendMsgRequest(String msgId, String bidId,String toUserId, String state, IAsyncHttpResponseHandler handler, LoadingHanlder loadingHanlder) {
        RequestParams params = new RequestParams();
//        params.put("msgId", UserAPI.getUserId());
        params.put("msgpid", msgId);
        params.put("bidId", bidId);
        params.put("touserId", "" + toUserId);
        params.put("state", state);

        post(ConstansUrl.RY_SEND_MSG_REQUEST, params, handler, RY_SEND_MSG_REQUEST, loadingHanlder);
    }


    /**
     * 专家
     *
     * @param pdid
     * @param msgpid
     * @param state
     * @param handler
     * @param loadingHanlder
     */
    public static void addExperts(String msgpid,String pdid,  String state, IAsyncHttpResponseHandler handler, LoadingHanlder loadingHanlder) {
        RequestParams params = new RequestParams();
//        params.put("msgId", UserAPI.getUserId());
        params.put("pdid", "" + pdid);
        params.put("msgpid", msgpid);
        params.put("state", state);

        post(ConstansUrl.ADD_EXPERTS, params, handler, ADD_EXPERTS, loadingHanlder);
    }

    public static void selectExpert( String msgpid,String pdid, String payable, String state, IAsyncHttpResponseHandler handler, LoadingHanlder loadingHanlder) {
        RequestParams params = new RequestParams();
//        params.put("msgId", UserAPI.getUserId());
        params.put("msgpid", msgpid);
        params.put("pdid", "" + pdid);
        params.put("payable", payable);
        params.put("state", state);

        post(ConstansUrl.SELECT_EXPERTS, params, handler, SELECT_EXPERTS, loadingHanlder);
    }

    public static void otherTeamMember(String teamCode, IAsyncHttpResponseHandler handler, LoadingHanlder loadingHandler) {
        RequestParams params = new RequestParams();
//        params.put("msgId", UserAPI.getUserId());
        params.put("pdid", "" + UserAPI.getUserId());
        params.put("teamCode", teamCode);
        get(ConstansUrl.OTHER_TEAM_MEMBER, params, handler, OTHER_TEAM_MEMBER, loadingHandler);
    }

}